import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.ticker as ticker

# 用来正常显示中文标签,黑体
plt.rcParams['font.sans-serif'] = 'SimHei'
# 字符显示,用来正常显示负号
plt.rcParams['axes.unicode_minus'] = False

#保存数据的文件
file = 'D:\shuju\三季度\论文\LF-3.csv'

#读取文件
data1=pd.read_csv(r'D:\shuju\三季度\论文\LF-3.csv')
#创建画布
f1=plt.figure(figsize=(10,6), facecolor='white',edgecolor='black',dpi=128)
plt.figure(1)
print(data1)
#x,y轴取值
x=data1['time']


# x = datetime.datetime(2022,09,20,0,0,0)
y1=data1['crack']
y2=data1['temperature']

print(len(y1))



labels1= []
for i1 in x:
    labels1.append(i1[:11])
#画布分格
a = plt.subplot(111)
plt.plot(x,y1,color="lightskyblue",label='裂缝')
plt.plot(x,y2,color="red",label='温度')
plt.xticks(x,labels1,rotation=20)
plt.tight_layout(pad=0.3)
a.xaxis.set_major_locator(ticker.MultipleLocator(200))
plt.ylabel("温度单位（℃）")
plt.legend(loc="upper left")
plt.twinx()
plt.ylim(0,0.5)
#标签
plt.xlabel("日期")
plt.ylabel("裂缝单位（mm）")
plt.title("裂缝-温度变化趋势图",fontsize=12, fontproperties='SimHei')
plt.tight_layout()
plt.show()